package com.cloudknow.intface;

import java.util.ArrayList;
import java.util.List;

public class ObserverTagManager implements SubjectTagListener {
    private static ObserverTagManager observerManager;
    //观察者接口集合
    private List<ObserverTagListener> list = new ArrayList<>();

    /**
     * 单例
     */
    public static ObserverTagManager getInstance(){
        if (null == observerManager){
            synchronized (ObserverTagManager.class){
                if (null == observerManager){
                    observerManager = new ObserverTagManager();
                }
            }
        }
        return observerManager;
    }

    /**
     * 加入监听队列
     */
    @Override
    public void add(ObserverTagListener observerListener) {
        list.add(observerListener);
    }

    /**
     * 通知观察者刷新数据
     */
    @Override
    public void notifyObserver(int position) {
        for (ObserverTagListener observerListener : list){
            observerListener.observerUpDataSelect(position);
        }
    }

    /**
     * 监听队列中移除
     */
    @Override
    public void remove(ObserverTagListener observerListener) {
        if (list.contains(observerListener)){
            list.remove(observerListener);
        }
    }
}
